using System;
using System.Globalization;
using System.Windows.Data;

namespace LDNS.UI.Converters
{
    /// <summary>
    /// 布尔值到文本转换器基类
    /// 作者: huobing
    /// </summary>
    public abstract class BooleanToTextConverter : IValueConverter
    {
        /// <summary>
        /// 转换为True时显示的文本
        /// </summary>
        protected abstract string TrueText { get; }

        /// <summary>
        /// 转换为False时显示的文本
        /// </summary>
        protected abstract string FalseText { get; }

        /// <summary>
        /// 转换布尔值为文本
        /// </summary>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is bool boolValue)
            {
                return boolValue ? TrueText : FalseText;
            }
            return FalseText;
        }

        /// <summary>
        /// 转换文本为布尔值（未实现）
        /// </summary>
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    /// <summary>
    /// 服务运行状态转换器
    /// 作者: huobing
    /// </summary>
    public class BooleanToRunningTextConverter : BooleanToTextConverter
    {
        protected override string TrueText => "运行中";
        protected override string FalseText => "已停止";
    }

    /// <summary>
    /// 连接状态转换器
    /// 作者: huobing
    /// </summary>
    public class BooleanToConnectedTextConverter : BooleanToTextConverter
    {
        protected override string TrueText => "已连接";
        protected override string FalseText => "未连接";
    }
}